package com.niodata.dp.task.dao;

import com.niodata.dp.task.entity.PluginExecTemplate;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface PluginExecTemplateMapper {

  @Insert("insert into PLUGIN_EXEC_TEMPLATE(ID,CREATE_TIME,OWNER_ID,"
      + "OWNER_TYPE,PLUGIN_NAME,PLUGIN_VERSION,TASK_NAME)"
      + "VALUES(#{temp.id},#{temp.createTime},#{temp.ownerId},"
      + "#{temp.ownerType},#{temp.pluginName},"
      + "#{temp.pluginVersion},#{temp.taskName})")
  public void save(@Param("temp") PluginExecTemplate template);

  @Delete("delete from PLUGIN_EXEC_TEMPLATE where ID =#{id}")
  public void delete(@Param("id") String id);


  @Select("select * from PLUGIN_EXEC_TEMPLATE where "
      + "OWNER_ID=#{ownerId} AND OWNER_TYPE=#{ownerType} "
      + "and PLUGIN_NAME=#{plugin} and PLUGIN_VERSION=#{version}")
  @ResultMap("execTemplateResultMap")
  public PluginExecTemplate getByOwnerId(@Param("ownerId") long ownerId,
      @Param("ownerType") String ownerType,
      @Param("plugin") String plugin,
      @Param("version") String version);


  @Select("select * from PLUGIN_EXEC_TEMPLATE where "
      + "OWNER_ID=#{ownerId} AND OWNER_TYPE=#{ownerType} "
      + "and PLUGIN_NAME=#{plugin}")
  @ResultMap("execTemplateResultMap")
  public List<PluginExecTemplate> getByOwnerIdAndName(@Param("ownerId") long ownerId,
      @Param("ownerType") String ownerType,
      @Param("plugin") String plugin);


  @Select("select * from PLUGIN_EXEC_TEMPLATE where "
      + "OWNER_ID=#{ownerId}")
  @ResultMap("execTemplateResultMap")
  public List<PluginExecTemplate> getTemplates(@Param("ownerId") long ownerId);

}
